export let tool = {
	runNumber: 0,
	debug: false,
	created: false,
	w: window.screen.availWidth,
	h: window.screen.availHeight,
	pc: true,
	time : {t1:150, t2: 250, t3:300, t4:450},
	space : '0.5rem',
	space2 : '0.3rem',
	radius : '0.12rem',
	scale : 1.015,
	FULL_WIDTH_REM : 750,
	fontSize : {h1:'0.4rem', h2:'0.32rem', h3:'0.26rem', h4:'0.2rem', h5:'0.16rem', 	h6:'0.12rem'},
	fontFamily : ["Helvetica Neue",'Helvetica',"PingFang SC","Hiragino Sans GB",	"Microsoft YaHei","微软雅黑",'Arial','sans-serif'],
	color : {main:'#222', bg:'#fff', higit:'#04f', disbel:'#666'},
	autoSize: 1,

	scroll: {
		overflow:'hidden',
		WebkitScrollbar: 'width:0',
	},

	//func
	changePc(){
		tool.pc = tool.w > 750? true : false
	},
	setRem(designWidth?: number){	
		if(!designWidth) designWidth = 750;
		let autoSize = 1;
		let doc = document, win = window;
		let docEl = doc.documentElement
		let resizeEvt = 'onorientationchange' in window ? 'onorientationchange' : 'resize'
		let recalc = function(){
			var clientWidth = docEl.clientWidth
			if (!clientWidth) return
			if (clientWidth > designWidth) {
				docEl.style.fontSize = '100px';
				autoSize = 1;
			} else {
				docEl.style.fontSize = 100 * (clientWidth / designWidth) + 'px'
				autoSize = (clientWidth / designWidth)
			}
		}
		if (!doc.addEventListener) return
		win.addEventListener(resizeEvt, recalc, false);
		doc.addEventListener('DOMContentLoaded', recalc, false)
		return autoSize
	},
	onload(){
		let body = document.getElementsByTagName('body')[0];
		body.style.margin = '0';
		body.style.border = '0';

		window.onload = function () {  
			document.addEventListener('touchstart',function (event) {  
				if(event.touches.length>1){  
					event.preventDefault();  
				}  
			})  
			var lastTouchEnd = 0;  
			document.addEventListener('touchend',function (event) {  
				var now=(new Date()).getTime();  
				if(now-lastTouchEnd<=300){  
					event.preventDefault();  
				}  
				lastTouchEnd=now;  
			},false)  
		}
	},
	assign(target:any, firstSource:any) {
		if (target === undefined || target === null) return null
		var to = Object(target);
		for (var i = 1; i < arguments.length; i++) {
			var nextSource = arguments[i];
			if (nextSource === undefined || nextSource === null) continue;
			var keysArray = Object.keys(Object(nextSource));
			for (var nextIndex = 0, len = keysArray.length; nextIndex < len; nextIndex++) {
			var nextKey = keysArray[nextIndex];
			var desc = Object.getOwnPropertyDescriptor(nextSource, nextKey);
			if (desc !== undefined) to[nextKey] = nextSource[nextKey];
			}
		}
		return to;
	},
	r(value: number) {
		return `${value / 100.0}rem`
	},
	lr(value: any) {
		let str = value.replace('rem', '');
		let num = parseFloat(str);
		return num * 100.0;
	},
	flex(obj: HTMLElement){
		obj.style.display = '-webkit-box';
		obj.style.display = '-webkit-flex';
		obj.style.display = 'flex';
		obj.style.position = 'absolute';
	},
	phone(obj: any){
		if(!tool.pc) {
			obj['-webkit-tap-highlight-color']='transparent';
			obj['-webkit-touch-callout'] = 'none';
			obj['-webkit-user-select'] = 'none';
			obj['-moz-user-select'] = 'none';
			obj['-ms-user-select'] = 'none';
		}
	},
	move(obj:any, x:number, y:number, z:number) {
		obj['WebkitTransform'] = `translate3d(${x}rem, ${y}rem, ${z}rem)`
		obj['transform'] = `translate3d(${x}rem, ${y}rem, ${z}rem)`
	},
	toFixed(obj:number, num:number) {
		let n = obj.toFixed(1)
		return n;
	}
}

if (tool.created === false) {
	tool.autoSize = tool.setRem()
	tool.onload()
	tool.changePc()
	tool.created = true
	console.log('tool set')
}

tool.runNumber ++
console.log(tool.runNumber)

